package com.demo.service.impl;

import com.demo.dao.OrderDao;
import com.demo.model.Order;
import com.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public int save(Order order) {
        return orderDao.insert(order);
    }

    @Override
    public Order getOrderById(Integer id) {
        return orderDao.selectOne(id);
    }
    @Override
    public List<Order> getOrderByUserId(Integer userId) {
        return orderDao.selectOneByUserId(userId);
    }

    @Override
    public Integer updateOrder(Order order) {
        if (order.getId() != null && order.getId() > 0) {
            return orderDao.update(order);
        }
        return orderDao.insert(order);
    }

    @Override
    public Integer deleteOrder(int id) {
        return orderDao.delete(id);
    }

    @Override
    public List<Order> getOrders(Integer userId) {
        return orderDao.select(userId);
    }
}
